<!-- My Bots -->
<!-- Author: Edwin -->
<template>
  <el-card shadow="never"
           class="aui-card--fill">
      <div v-loading="loading">
        <div class="title"
           style="display:flex;justify-content:space-between;width:30vw">
        <div style="height:32px;line-height:32px;font-size:16px">{{'Sync Data Refresh'}}</div>
      </div>
      <el-divider></el-divider>
      <div v-for="(item,index) in dataList" style="width:30vw;margin-bottom:15px"
           :key="index">
        <div class="title"
             style="display:flex;justify-content:space-between">
          <div style="height:32px;line-height:32px">{{item.dictLabel}}</div>
          <el-button size="small"
                     type="primary"
                     @click="sycn(item)">{{'Refresh Now'}}</el-button>
        </div>
      </div>
      </div>
  </el-card>
</template>
<script>

export default {
  data () {
    return {
      loading: false
    }
  },
  computed: {
    dataList () {
      let temp = []
      try {
        temp = window.SITE_CONFIG['dictList'].find(e => e.dictType === 'refersh_sync_group').dataList
      } catch (error) {

      }
      return temp
    }
  },
  created () {
  },
  methods: {
    sycn (data) {
      switch (data.subjectCode) {
        case 'get':
          this.loading = true
          this.$http['get'](data.dictValue).then(({ data: res }) => {
            if (res.code !== 0) {
              return this.$message.error(res.msg)
            }
            this.loading = false
            this.$message.success(res.msg)
          })
          break
        case 'post':
          this.$http['post'](data.dictValue).then(({ data: res }) => {
            if (res.code !== 0) {
              return this.$message.error(res.msg)
            }
            this.loading = false
            this.$message.success(res.msg)
          })
          break
        case 'put':
          this.$http['put'](data.dictValue).then(({ data: res }) => {
            if (res.code !== 0) {
              return this.$message.error(res.msg)
            }
            this.loading = false
            this.$message.success(res.msg)
          })
          break
        default:
          break
      }
    }
  }
}
</script>
<style scoped>
</style>
